package cur.nature.admin.dao;

import cur.nature.admin.common.config.DBAdminConfig;
import cur.nature.admin.model.vo.Admin_DictVO;
import cur.nature.framework.core.log.LOG;
import cur.nature.framework.core.util.StringUtil;
import cur.nature.tinyorm.core.bean.PageBean;
import cur.nature.tinyorm.core.template.DefaultJdbcTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import static cur.nature.admin.common.conts.DatabaseConst.DRIVER_CLASS_NAME;
import static cur.nature.admin.common.conts.DatabaseConst.DRIVER_SQLITE;

/**
 * 通用字典表 Dao
 * 作者：Auto Generator By wujian
 * 生成日期：2023-07-09 16:05:31
 */
@Component
@Primary
@DependsOn(DefaultJdbcTemplate.TEMPLATE)
@ConditionalOnExpression("#{'${"+ DRIVER_CLASS_NAME +"}'.equals('"+DRIVER_SQLITE+"')}")
public class Admin_DictDao_Sqlite extends Admin_DictDao {
    public Admin_DictDao_Sqlite(@Qualifier(DBAdminConfig.TEMPLATE) DefaultJdbcTemplate template) {
        super(template);
        LOG.info("初始化 sqlite 组件");
    }

    @Override
    public PageBean<Admin_DictVO> list(Admin_DictVO.list_Param param) throws Exception {
        LOG.info("现在进入 sqlite .....");
        StringBuilder condition = new StringBuilder(" 1=1 ");
        if(StringUtil.isNotEmpty(param.getKeyword())){
            condition.append(" and a.code like '"+param.getKeyword()+"%' ");
        }
        String sql = "select " + this.cols() + " from " + tableName() + " a " + " where " + condition;
        PageBean<Admin_DictVO> list = queryForPage(sql, param.buildPage(),
                null, Admin_DictVO.class);
        LOG.info("现在退出 sqlite .....");
        return list;
    }

}

